package com.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuxuhuang
 * @date 2023年03月31日 22:59
 */
public enum FormOperateEnum {
    /**
     * 注册操作表单
     */
    ERGISTER("REGISTER", "注册"),
    /**
     * 登录操作表单
     */
    LOGIN("LOGIN", "登录"),
    /**
     * 重置密码
     */
    RESETPWD("RESETPWD","重置密码");

    private String code;

    private String name;

    public static List<Map<String, Object>> toList() {
        List<Map<String, Object>> result = new ArrayList<>();
        for (FormOperateEnum e : FormOperateEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", e.getCode());
            map.put("value", e.getName());
            result.add(map);
        }
        return result;
    }

    public static String getNameByCode(String code) {
        for (FormOperateEnum value : values()) {
            if (value.code.equals(code)) {
                return value.name;
            }
        }
        return "未知";
    }

    FormOperateEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}
